package com.stx.boke.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.stx.boke.dao.UserDao;
import com.stx.boke.dao.impl.UserDaoImpl;
import com.stx.boke.entity.Blogger;
import com.stx.boke.entity.User;

/**
 * Servlet implementation class RegistUser
 */
public class Report extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserDao ud = new UserDaoImpl();   
    /**
     * @see HttpServlet#HttpServlet()
     */
	
	
//	@Override
//	public void init() throws ServletException {
//		// 初始化用户Dao对象
//		ud = new UserDaoImpl();
//	}
	
	
    public Report() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
//		String bid=request.getParameter(bid);
		String cid= request.getParameter("cid");
		String content = request.getParameter("content");
		String title = request.getParameter("title");
		User user =  (User) request.getSession().getAttribute("USER");
//		String usid =session.getAttribute("USER", usid);//用ssion获取
//		HttpSession session = request.getSession();
//		session.setAttribute("USER", loginuser); 
//		String level=request.getParameter("level");
//		<%-- 从session(会话)对象中获得当前已登录用户对象 --%>
//		<% User currentUser = (User)session.getAttribute("currentUser"); %>
		

//		String createtime = GetTime.getTime();//获取时间
		

		Blogger blogger = new Blogger();
		blogger.setCid(cid);
		blogger.setContent(content);
		blogger.setTitle(title);
		blogger.setUsid(user.getUsid());
//		user.setCreatetime(createtime);




		
		
		int addblo = ud.addBlogger(blogger);
		if(addblo==1){
		
			System.out.println("发表成功！");
			response.sendRedirect("/kqblog/jsp/mereport.jsp");
		}else{
			System.out.println("发表失败！");
			response.sendRedirect("/kqblog/jsp/report.jsp");
			
		}
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

